<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>layui.form小例子</title>
<link rel="stylesheet" href="libs/layuimodel/css/layui.css" media="all">
</head>
<body>
<form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
  <div class="layui-form-item">
    <label class="layui-form-label">产品名字</label>
    <div class="layui-input-block">
      <input type="text" name="mingzi" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">产品价格</label>
    <div class="layui-input-block">
      <input type="text" name="jiage" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">所属类别</label>
    <div class="layui-input-block">
      <select name="leibie" lay-filter="leibie">
        <option value="1">测试1</option>
        <option value="2">测试2</option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">图片url</label>
    <div class="layui-input-block">
      <input type="text" name="imgurl" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">颜色</label>
    <div class="layui-input-block">
      <select name="yanse" lay-filter="yanse">
        <option value="1">黑色</option>
        <option value="2">白色</option>
        <option value="3">绿色</option>
        <option value="4">蓝色</option>
        <option value="5">棕色</option>
        <option value="6">红色</option>
        <option value="7">紫色</option>
        <option value="8">灰色</option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">是否精选</label>
    <div class="layui-input-block">
      <input type="radio" name="jingxuan" value="0" title="否">
      <input type="radio" name="jingxuan" value="1" title="是" checked>
    </div>
  </div> 
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script type="text/javascript" src="libs/layuimodel/layui.js"></script>
<script>
layui.use('form', function(){
  var form = layui.form;
  var $=layui.jquery;
  form.on('submit(*)', function(data){	
	  console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
	  $.ajax({
		  url:"chanpinadd",
		  type:"post",
		  data:data.field,
		  success:function(res){
			  if(res=="1"){
				  layer.msg("添加成功");
			  }		  
			  else{
				  layer.msg("添加失败");
			  }
		  }
	  });
	  
	  
	  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	});
  //各种基于事件的操作，下面会有进一步介绍
});
</script>
</body>
</html>